﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Tetris
{
    class client
    {
        string nickname;
        StreamReader sr;
        StreamWriter sw;
        TcpClient connection = new TcpClient();

        public client(IPAddress ipv4, int port, string nickname) 
        {
            this.nickname = nickname;
            connection.Connect(ipv4, port);
        }

        public void Write(string message) 
        {
            if (connection.Connected)
            {
                sw = new StreamWriter(connection.GetStream());
                sr = new StreamReader(connection.GetStream());
                sw.WriteLine("{0}: {1}", nickname, message);
                sw.Flush();
            }
            else
                throw new Exception("Server not ready");
        }
        public void Close() 
        {
            sw.Close();
            sr.Close();
            connection.Close();
        }
    }
}
